package com.yicong.ants.view;

import androidx.core.content.ContextCompat;
import androidx.databinding.BindingAdapter;

import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;

import com.alibaba.security.common.view.GifImageView;
import com.cchao.simplelib.view.DrawableCenterTextView;
import com.yicong.ants.R;
import com.yicong.ants.manager.ImageHelper;
import com.yicong.ants.manager.UserManager;

/**
 * databinging 的自定义 属性转化
 *
 * @author : cchao
 * @version 2019-04-17
 */
public class BindingAdapters {

    @BindingAdapter(value = {"right_label"}, requireAll = false)
    public static void setRigthLabel(GeneralItemView view, String text) {
        view.setRightLabel(text);
    }

    @BindingAdapter(value = {"label_value"}, requireAll = false)
    public static void setLabelValue(GeneralItemView view, String text) {
        view.setValue(text);
    }

    @BindingAdapter(value = {"round4_url"}, requireAll = false)
    public static void roundImageUrl4(ImageView view, String url) {
        ImageHelper.loadImageRound(view, url, 4);
    }

    @BindingAdapter(value = {"round2_url"}, requireAll = false)
    public static void roundImageUrl2(ImageView view, String url) {
        ImageHelper.loadImageRound(view, url, 2);
    }

    @BindingAdapter(value = {"src_url"})
    public static void srcUrl(ImageView view, String url) {
        ImageHelper.loadImage(view, url);
    }

    @BindingAdapter(value = {"round_url" , "round"}, requireAll = false)
    public static void roundImageUrl(ImageView view, String url , int round) {
        ImageHelper.loadImageRound(view, url, round);
    }

    @BindingAdapter(value = {"round_url" , "round" , "default"}, requireAll = false)
    public static void roundImageUrl(ImageView view, String url , int round , int def) {
        ImageHelper.loadImageRound(view, url, round , def);
    }

    @BindingAdapter(value = {"round_url" , "round" , "default" , "frameColor" , "frameWidth"}, requireAll = true)
    public static void roundImageAndFrameUrl(ImageView view, String url , int round , int def , int frameColor , int frameWidth) {
        ImageHelper.loadImageRound(view, url, round , def , frameColor , frameWidth);
    }

    @BindingAdapter(value = {"image_url"}, requireAll = false)
    public static void imageUrl(ImageView view, String url) {
        ImageHelper.loadImage(view, url);
    }

    @BindingAdapter(value = {"levelDrawable"})
    public static void levelDrawable(ImageView view, String level) {
        if (level == null)
            return;
        switch (level) {
            case "1":
                view.setImageResource(R.drawable.level_1_ic);
                break;
            case "2":
                view.setImageResource(R.drawable.level_2_ic);
                break;
            case "3":
                view.setImageResource(R.drawable.level_3_ic);
                break;
            case "4":
                view.setImageResource(R.drawable.level_4_ic);
                break;
            case "5":
                view.setImageResource(R.drawable.level_5_ic);
                break;

        }
    }

    @BindingAdapter(value = {"levelDrawable2"})
    public static void levelDrawable2(ImageView view, String level) {
//        if (level == null)
//            return;
//        switch (level) {
//            case "0":
//                view.setImageResource(R.drawable.level_0_ic);
//                break;
//            case "1":
//                view.setImageResource(R.drawable.level_1_ic);
//                break;
//            case "2":
//                view.setImageResource(R.drawable.level_2_ic);
//                break;
//            case "3":
//                view.setImageResource(R.drawable.level_3_ic);
//                break;
//            case "4":
//                view.setImageResource(R.drawable.level_4_ic);
//                break;
//            case "5":
//                view.setImageResource(R.drawable.level_5_ic);
//                break;
//        }
    }
}
